package dbPhase.hypeerweb;

import org.junit.Test;
import junit.framework.TestCase;

public class NodeTest extends TestCase {

	@Test
	public void testAddDownPointer() {
		Node node5 = new Node(5);
		Node node7 = new Node(7);

		node5.addDownPointer(node7);
		assertTrue(node5.downPointers.contains(node7));
		assertFalse(node5.downPointers.contains(node5));
	}

	@Test
	public void testAddNeighbor() {
		Node node5 = new Node(5);
		Node node7 = new Node(7);
		Node node6 = new Node(6);

		node5.addNeighbor(node7);
		node5.addNeighbor(node6);
		assertTrue(node5.neighbors.contains(node7));
		assertTrue(node5.neighbors.contains(node6));
		assertFalse(node5.neighbors.contains(node5));
	}

	@Test
	public void testAddUpPointer() {
		Node node5 = new Node(5);
		Node node7 = new Node(7);
		Node node6 = new Node(6);

		node5.addUpPointer(node7);
		node5.addUpPointer(node6);
		assertTrue(node5.upPointers.contains(node7));
		assertTrue(node5.upPointers.contains(node6));
		assertFalse(node5.upPointers.contains(node5));
	}

	@Test
	public void testConstructSimplifiedNodeDomain() {
		Node node = new Node(3);
		Node node5 = new Node(5);
		Node node7 = new Node(7);

		SimplifiedNodeDomain simpleDomain = node.constructSimplifiedNodeDomain();
		SimplifiedNodeDomain simpleDomain2 = node5.constructSimplifiedNodeDomain();
		SimplifiedNodeDomain simpleDomain3 = node7.constructSimplifiedNodeDomain();

		assertTrue(simpleDomain.getWebId() == 3);
		assertTrue(simpleDomain2.getWebId() == 5);
		assertTrue(simpleDomain3.getWebId() == 7);
	}

	@Test
	public void testGetWebId() {
		Node node = new Node(3);
		Node node5 = new Node(300);
		Node node7 = new Node(0);

		assertTrue(node.webId.getValue() == 3);
		assertTrue(node5.webId.getValue() == 300);
		assertTrue(node7.webId.getValue() == 0);
	}

	@Test
	public void testRemoveDownPointer() {
		Node node5 = new Node(5);
		Node node7 = new Node(7);

		node5.addDownPointer(node7);
		assertTrue(node5.downPointers.contains(node7));
		assertFalse(node5.downPointers.contains(node5));

		node5.removeDownPointer(node7);
		assertFalse(node5.downPointers.contains(node7));
	}

	@Test
	public void testRemoveNeighbor() {
		Node node5 = new Node(5);
		Node node7 = new Node(7);
		Node node6 = new Node(6);

		node5.addNeighbor(node7);
		node5.addNeighbor(node6);
		assertTrue(node5.neighbors.contains(node7));
		assertTrue(node5.neighbors.contains(node6));

		node5.removeNeighbor(node6);
		assertTrue(node5.neighbors.contains(node7));
		assertFalse(node5.neighbors.contains(node6));
	}

	@Test
	public void testRemoveUpPointer() {
		Node node5 = new Node(5);
		Node node7 = new Node(7);
		Node node6 = new Node(6);

		node5.addUpPointer(node7);
		node5.addUpPointer(node6);



		assertTrue(node5.upPointers.contains(node7));
		assertTrue(node5.upPointers.contains(node6));
		assertFalse(node5.upPointers.contains(node5));

		node5.removeUpPointer(node7);
		assertFalse(node5.upPointers.contains(node7));

		node5.removeUpPointer(node6);
		assertFalse(node5.upPointers.contains(node6));
	}

	@Test
	public void testSetFold() {
		Node node5 = new Node(5);
		Node node7 = new Node(7);
		Node node6 = new Node(6);

		node5.setFold(node7);
		node6.setFold(node5);

		assertTrue(node5.fold.getWebId().getValue() == 7);
		assertTrue(node6.fold.getWebId().getValue() == 5);
		assertFalse(node5.fold.getWebId().getValue() == 8);
	}

	@Test
	public void testSetInverseSurrogateFold() {
		Node node5 = new Node(5);
		Node node7 = new Node(7);
		Node node6 = new Node(6);

		node5.setInverseSurrogateFold(node7);
		node6.setInverseSurrogateFold(node5);

		assertTrue(node5.inverseSurrogateFold.getWebId().getValue() == 7);
		assertTrue(node6.inverseSurrogateFold.getWebId().getValue() == 5);
		assertFalse(node5.inverseSurrogateFold.getWebId().getValue() == 8);
	}

	@Test
	public void testSetSurrogateFold() {
		Node node5 = new Node(5);
		Node node7 = new Node(7);
		Node node6 = new Node(6);

		node5.setSurrogateFold(node7);
		node6.setSurrogateFold(node5);

		assertTrue(node5.surrogateFold.getWebId().getValue() == 7);
		assertTrue(node6.surrogateFold.getWebId().getValue() == 5);
		assertFalse(node5.surrogateFold.getWebId().getValue() == 8);
	}

	@Test
	public void testSetWebId() {
		Node node5 = new Node(5);
		Node node7 = new Node(7);

		WebId node5id = new WebId(9);
		WebId node7id = new WebId(7);

		node5.setWebId(node5id);
		node7.setWebId(node7id);

		assertTrue(node5.getWebId().getValue()==9);
		assertTrue(node7.getWebId().getValue()==7);
	}

}
